{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ROC曲线"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from matplotlib import pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\annaconda\\lib\\site-packages\\sklearn\\linear_model\\_logistic.py:940: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)\n"
     ]
    }
   ],
   "source": [
    "from sklearn import datasets\n",
    "\n",
    "digits = datasets.load_digits()\n",
    "X = digits.data\n",
    "y = digits.target.copy()\n",
    "\n",
    "y[digits.target==9] = 1           #生成有偏的数据集\n",
    "y[digits.target!=9] = 0\n",
    "from sklearn.model_selection import train_test_split\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=666)\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "log_reg = LogisticRegression()\n",
    "log_reg.fit(X_train, y_train)\n",
    "decision_scores = log_reg.decision_function(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from playML.metrics import FPR, TPR\n",
    "\n",
    "fprs = [] \n",
    "tprs = []\n",
    "thresholds = np.arange(np.min(decision_scores), np.max(decision_scores), 0.1)\n",
    "for threshold in thresholds:\n",
    "    y_predict = np.array(decision_scores >= threshold, dtype='int')\n",
    "    fprs.append(FPR(y_test, y_predict))\n",
    "    tprs.append(TPR(y_test, y_predict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0xb623360fc8>]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAQaklEQVR4nO3df4xdZZ3H8fe305aqFFBnKGx/OCW2hhHZBSeE1Y1AUFNq0saNmtYlLrusje7i/qHZhI27rMHsH2JWE2P90bgGNVFEE3XiVsmulLBxrTIGRVosjgXtCLYDIoiUttP57h/34t6due09w9w7d+4z71cyyT3nPL338/ROPxzOPefcyEwkSb1vSbcDSJLaw0KXpEJY6JJUCAtdkgphoUtSIZZ264X7+/tzcHCwWy8vST3phz/84WOZOdBsW9cKfXBwkNHR0W69vCT1pIj4xam2echFkgphoUtSISx0SSqEhS5JhbDQJakQLQs9Ij4bEUci4v5TbI+I+FhEjEXEfRFxaftjSpJaqbKHfiuw6TTbrwE21H92AJ+ceyxJ0my1PA89M++OiMHTDNkKfD5r9+HdGxHnRMT5mflomzKqTR567Pd87d5fgbdMlrrq6gtX8cdrz2n787bjwqLVwKGG5fH6uhmFHhE7qO3Fs27duja8tGbjQ9/6Kd/e92siup1EWtzOPWvFgi30ZvXQdBcwM3cBuwCGh4fdTZxHTx+bZM+BI1z3mkE+sOWV3Y4jqQPacZbLOLC2YXkN8Egbnldt9J0HDnNscoo3XXx+t6NI6pB2FPoI8I762S6XA096/LzzpqaSyZNTlX/+475HWXXWGbx63Yu7HV1Sh7Q85BIRXwKuBPojYhz4F2AZQGZ+CtgNbAbGgGeAv+pUW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4dUnk9EXAsMA1d0NFHnnXbOEbGE2vfUXjdfgeZBlfd5KbXDLldS+7+w/46IizLztx3O1ilV5rwduDUz/y0i/pTaHVwvysypzsfrirb310LeQ1+MX6xRZc5ExOuB9wNbMvPYPGXrlFZzXglcBNwVEQ9TO9Y40uMfjFb93f5GZp7IzIeAA9QKvldVmfP1wO0Amfk9YAW1m1iVqtK/99lYyIW+GL9Yo+Wc64cfPk2tzHv9uCq0mHNmPpmZ/Zk5mJmD1D432JKZo92J2xZVfre/Tu0DcCKin9ohmIPzmrK9qsz5l8DVABFxIbVCL/nLh0eAd9TPdrkceDIzH53TM3b7k+AWnxJvBh6k9un4++vrbqb2Dxpqb/hXgDHgB8AF3c48D3P+L+Aw8KP6z0i3M3d6ztPG3kWPn+VS8X0O4CPAfuAnwLZuZ56HOQ8B36V2BsyPgDd2O/Mc5/sl4FHgBLW98euBdwHvaniPd9b/Pn7Sjt9rL/2XpEIs5EMukqRZsNAlqRAWuiQVwkKXpEJY6JJUCAtdkgphoUtSIf4XDzS19N5EECYAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(fprs, tprs)      #对于ROC曲线，通常关注的是曲线与坐标轴所围面积的大小"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### sklearn 中的ROC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import roc_curve\n",
    "fprs, tprs, thresholds = roc_curve(y_test, decision_scores)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0xb62330fb88>]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAA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aer7E+ST/X/PR5J8oZLftGquix/6H1V738BrwGuBL4HzK5o8+fAp/vLh4EvTbruTejzW4Df6i+/fyv0ud/uKuBbwElgbtJ1b8L7vA94CPid/vorJ133JvT5OPD+/vIs8MNJ132Jff4D4A3AD1bZfwvwdXpPfLsROHWpr3k5j9C34sOpR/a5qh6oqp/1V0/Se4LUNOvyPgN8DPg48PPNLG6DdOnze4FjVfUcQFU9s8k1jluXPhdw/qHBL+PCJ6NNlar6Fms/ue0Q8PnqOQm8PMk1l/Kal3OgD3s49Y7V2lTVi8D5h1NPqy59HnQbvf/CT7ORfU5yPbCrqr62mYVtoC7v87XAtUm+neRkkgObVt3G6NLnjwK3Jlmi9/yFD2xOaROz3r/3kTo94GJCxvZw6inSuT9JbgXmgDdvaEUbb80+J3kJ8EngPZtV0Cbo8j5vozftchO9/wv79yTXVdX/bHBtG6VLn48An6uqv0vyRnpPQbuuqv5348ubiLHn1+U8Qt+KD6fu0meSvA34MHCwqn6xSbVtlFF9vgq4Dvhmkh/Sm2ucn/ITo10/2/dV1S+r6jHgLL2An1Zd+nwbcC9AVX0HeCm9L7FqVae/9/W4nAN9Kz6cemSf+9MPn6EX5tM+rwoj+lxVz1fV9qraU1V76J03OFhVC5Mpdyy6fLa/Su8EOEm205uCObepVY5Xlz4/DrwVIMlr6QX68qZWubnmgXf3r3a5EXi+qp6+pCNO+kzwiLPEtwD/Se/s+If72+6i9wcNvTf8y8Ai8B/AayZd8yb0+V+B/wYe7v/MT7rmje7zirbfZMqvcun4Pgf4e+AM8H3g8KRr3oQ+zwLfpncFzMPAH0265kvs7xeBp4Ff0huN3wa8D3jfwHt8rP/v8f1xfK699V+SGnE5T7lIktbBQJekRhjoktQIA12SGmGgS1IjDHRJaoSBLkmN+D8t6E6VLjqlsAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(fprs, tprs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ROC AUC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9823319615912208"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.metrics import roc_auc_score\n",
    "roc_auc_score(y_test, decision_scores)              #ROC曲线与x轴所围区域的面积值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
